﻿@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@using IdServer.Resources
@using Microsoft.Extensions.Options
@using System.Globalization

@inject IOptions<SimpleIdServer.IdServer.Options.IdServerHostOptions> Options

@{
    var returnUrl = string.IsNullOrEmpty(Context.Request.Path) ? "~/" : $"~{Context.Request.Path.Value}{Context.Request.QueryString}";
    var currentCultureInfo = CultureInfo.DefaultThreadCurrentUICulture;
    string languagesLabel = LayoutResource.ResourceManager.GetString("languages");
    if (currentCultureInfo != null && !string.IsNullOrWhiteSpace(currentCultureInfo.Name))
    {
        var str = LayoutResource.ResourceManager.GetString(currentCultureInfo.Name);
        if (!string.IsNullOrWhiteSpace(str))
        {
            languagesLabel = string.Format(LayoutResource.ResourceManager.GetString("selected_language"), str);
        }
    }
    Layout = "~/Views/Shared/_CommonLayout.cshtml";
}

<nav class="navbar navbar-expand-lg bg-primary">
    <div class="container-fluid">
        <a class="navbar-brand" href="#">
			<img src="~/images/SIDLogo.svg" width="40px" />
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav me-auto">
                @if (User.Identity.IsAuthenticated)
                {
                    <li class="nav-item">
                        <a class="nav-link" href="@Url.Action("Profile", "Home")">
                            Welcome @User.Identity.Name
                        </a>
                    </li>
                }
                @RenderSection("SubMenu", required: false)
            </ul>
            <ul class="navbar-nav">
                @if(User.Identity.IsAuthenticated)
                {
                    <li class="nav-item">
                        <a class="nav-link" href="@Url.Action("Disconnect", "Home", new { area = "" })">@LayoutResource.disconnect</a>
                    </li>
                }
                else
                {                    
                    <li class="nav-item">
                        <a class="nav-link" href="@Url.Action("Profile", "Home", new { area = "" })">@LayoutResource.authenticate</a>
                    </li>
                }
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" data-bs-toggle="dropdown">
                        @languagesLabel
                    </a>
                    <div class="dropdown-menu">
                        @foreach (var uiCulture in Options.Value.SupportedUICultures)
                        {
                            <form asp-controller="Home" asp-action="SwitchLanguage" asp-area="" method="post">
                                <input type="hidden" name="culture" value="@uiCulture.Name" />
                                <input type="hidden" name="returnUrl" value="@returnUrl" />
                                <button type="submit" class="dropdown-item" href="#">@LayoutResource.ResourceManager.GetString(uiCulture.Name)</button>
                            </form>
                        }
                    </div>
                </li>
            </ul>
        </div>
    </div>
</nav>
<div id="container">
    <div>
        @RenderSection("PageTitle", false)
    </div>
    <div>
        @RenderBody()
    </div>
</div>

@section Scripts {
    @RenderSection("Scripts", required: false)
}